home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / Directory source / Init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-27  |  2.1 KB  |  125 lines  |  [TEXT/KAHL]

  1. /*    INIT.C
  2.  *
  3.  *    This contains the code which initializes the sample application
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include "res.h"
  8. #include "struct.h"
  9. #include "error.h"
  10.  
  11.  
  12. MenuHandle applMenu,fileMenu,editMenu;
  13. unsigned char ColorQD,MultiWidget;        /* State flags */
  14.  
  15. #define TRAP_WNE    0x060
  16. #define TRAP_UNIMP    0x09F
  17.  
  18.  
  19. /*    InitApp
  20.  *
  21.  *    The entry point for application initialization
  22.  */
  23.  
  24. InitApp()
  25. {
  26.     int i;
  27.  
  28.     InitMacOS();                        /* Step 1:  Initialize the macintosh */
  29.  
  30.     if (i = Catch()) {                    /* Step 2:    Trap errors; if a problem comes */
  31.         PostError(i);                    /*            up, simply exit to shell and */
  32.         ExitToShell();                    /*            forget it. */
  33.     }
  34.  
  35.     InitEnv();                            /* Step 2:  Get environment stuff */
  36.     InitMenuBar();                        /* Step 3:  Initialize the menu bar */
  37.     InitGlobals();                        /* Step 4:  Initialize globals */
  38.     
  39.     Uncatch();                            /* Step 5:    All done.  Forget the error trap */
  40. }
  41.  
  42.  
  43.  
  44. /*    InitMacOS
  45.  *
  46.  *    Bring up the Macintosh operating system as per Inside Macintosh
  47.  */
  48.  
  49. InitMacOS()
  50. {
  51.     InitGraf(&thePort);
  52.     InitCursor();
  53.     InitFonts();
  54.     InitWindows();
  55.     InitMenus();
  56.     TEInit();
  57.     InitDialogs(NULL);
  58.     FlushEvents(everyEvent,0);
  59. }
  60.  
  61.  
  62. /*    InitEnv
  63.  *
  64.  *    Get environment state.  The various things to test for include
  65.  *
  66.  *        •    Multifinder environment?
  67.  *        •    Color quickdraw present?
  68.  */
  69.  
  70. InitEnv()
  71. {
  72.     SysEnvRec theWorld;
  73.     OSErr err;
  74.     short i;
  75.     Handle h;
  76.  
  77.     err = SysEnvirons(1,&theWorld);
  78.     if (theWorld.hasColorQD) ColorQD = 1;
  79.     else ColorQD = 0;
  80.  
  81.     if ((theWorld.machineType >= 0) && 
  82.         (NGetTrapAddress(TRAP_WNE,ToolTrap) != NGetTrapAddress(TRAP_UNIMP,ToolTrap)))
  83.         MultiWidget = 1;
  84.     else MultiWidget = 0;
  85. }
  86.  
  87.  
  88. /*    InitMenuBar
  89.  *
  90.  *    Turn on the menu bar
  91.  */
  92.  
  93. InitMenuBar()
  94. {
  95.     applMenu = GetMenu(APPLMENU);
  96.     AddResMenu(applMenu,'DRVR');
  97.     fileMenu = GetMenu(FILEMENU);
  98.     editMenu = GetMenu(EDITMENU);
  99.  
  100.     InsertMenu(applMenu,0);
  101.     InsertMenu(fileMenu,0);
  102.     InsertMenu(editMenu,0);
  103.  
  104.     DrawMenuBar();
  105. }
  106.  
  107.  
  108.  
  109. /*    InitGlobals
  110.  *
  111.  *    Initialize any application globals
  112.  *        •    struct WindDraw drawList
  113.  */
  114.  
  115. InitGlobals()
  116. {
  117.     int i;
  118.     
  119.     drawList = (struct WindDraw *)NewPtr(MAXWINDOWS * sizeof(struct WindDraw));
  120.     if (drawList == NULL) Throw(INITOUTMEM);
  121.     for (i = 0; i < MAXWINDOWS; i++) drawList[i].inuse = 0;
  122.     
  123.     GetMounted();
  124. }
  125.